<template>
    <view class="bg-white margin-xs radius-lg">
        <block>
            <view class="flex padding-tb-sm">
                <view class="flex-treble">
                    <view class="flex">
                        <view class="padding-lr-sm">
                            <MrAvatar :src="nurseItem.avatar" :size="148"></MrAvatar>
                        </view>
                        <view class="padding-xs text-xl text-black">
                            <view class="text-bold text-cut" style="width: 30vw">{{ nurseItem.name }}</view>
                            <view class="text-red text-sm padding-tb-xs">
                                主治
                            </view>
                            <view class="text-gray text-sm">
                                {{ nurseItem.hospital }}
                            </view>
                        </view>
                    </view>
                </view>
                <view class="flex-sub">
                    <view class="flex justify-end text-black text-xxl">
                        <view class="cuIcon-message padding-sm padding-top-lg" @click.stop="handleChat"></view>
                        <view class="cuIcon-phone padding-sm padding-top-lg" @click.stop="handlePhone"></view>
                    </view>
                </view>
            </view>
        </block>
    </view>
</template>

<script setup lang="ts">

import {defineProps} from "vue";
import api from "@/api";
import MrAvatar from "@/components/common/MrAvatar.vue";
import {useUserStore} from "@/store";


const userStore = useUserStore()
const props = defineProps({
    nurseItem: {
        type: Object,
        default: {}
    }
})


/**
 * 电话咨询
 * @param item
 */
const handlePhone = () => {
    uni.makePhoneCall({
        phoneNumber: props.nurseItem.phone
    })
}
/**
 * 图文咨询
 * @param row
 */
const handleChat = () => {
    if (userStore.userInfo.status === 3 || userStore.userInfo.status === 33 || userStore.userInfo.status === 333) {
        uni.showToast({
            icon: 'error',
            title: '暂不支持医护之间咨询'
        })
        return
    }
    api.patient.info({}).then(response => {
        if (response && response.data.code === 0) {
            if (response.data.data === null) {
                uni.redirectTo({
                    url: '/pages/patient/info/create',
                    success: () => {
                        uni.showToast({
                            icon: 'error',
                            title: '请先完善身份',
                        })
                    }
                })
            } else {
                api.chat.createFriends({
                    fromUsername: response.data.data.username,
                    fromName: response.data.data.name,
                    fromAvatar: response.data.data.avatar,
                    toUsername: props.nurseItem.username,
                    toName: props.nurseItem.name,
                    toAvatar: props.nurseItem.avatar,
                }).then(res => {
                    let params = {
                        chatFriends: res.data.data
                    }
                    uni.navigateTo({
                        url: '/pages/common/chat/chat?params=' + encodeURIComponent(JSON.stringify(params))
                    })
                })
            }
        }
    })
}

</script>

<style scoped>

</style>